home *** CD-ROM | disk | FTP | other *** search
- /*
- * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
- * ALL RIGHTS RESERVED
- * Permission to use, copy, modify, and distribute this software for
- * any purpose and without fee is hereby granted, provided that the above
- * copyright notice appear in all copies and that both the copyright notice
- * and this permission notice appear in supporting documentation, and that
- * the name of Silicon Graphics, Inc. not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission.
- *
- * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
- * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
- * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
- * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
- * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
- * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
- * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
- * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
- * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * US Government Users Restricted Rights
- * Use, duplication, or disclosure by the Government is subject to
- * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
- * (c)(1)(ii) of the Rights in Technical Data and Computer Software
- * clause at DFARS 252.227-7013 and/or in similar or successor
- * clauses in the FAR or the DOD or NASA FAR Supplement.
- * Unpublished-- rights reserved under the copyright laws of the
- * United States. Contractor/manufacturer is Silicon Graphics,
- * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
- *
- * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
- */
-
- /* this file contains miscellaneous tk functions ported to aux */
-
- #include <aux.h>
- #include <auxPrivate.h>
- #include <string.h>
-
- #if defined(__cplusplus) || defined(c_plusplus)
- #define class c_class
- #endif
-
-
- void auxCloseWindow(void)
- {
- auxWinClose( auxState.current->id );
- }
-
- Display *auxXDisplay(void)
- {
- return (auxState.display);
- }
-
- Window auxXWindow(void)
- {
-
- return (auxState.current->glxWindow);
- }
-
- /* bit bucket for errors generated when setting colors */
- static int Ignore(Display *parm1, XErrorEvent *parm2)
- {
- return 0;
- }
-
-
- /* ported from tkSetOneColor() */
- void auxSetOneColor(int index, float r, float g, float b)
- {
- XErrorHandler old_handler;
- XColor c;
- int rShift, gShift, bShift;
-
- old_handler = XSetErrorHandler(Ignore);
- switch (auxState.current->glxVisual->class) {
- case DirectColor:
- rShift = ffs((unsigned int)auxState.current->glxVisual->red_mask) - 1;
- gShift = ffs((unsigned int)auxState.current->glxVisual->green_mask) - 1;
- bShift = ffs((unsigned int)auxState.current->glxVisual->blue_mask) - 1;
- c.pixel = ((index << rShift) & auxState.current->glxVisual->red_mask) |
- ((index << gShift) & auxState.current->glxVisual->green_mask) |
- ((index << bShift) & auxState.current->glxVisual->blue_mask);
- c.red = (unsigned short)(r * 65535.0 + 0.5);
- c.green = (unsigned short)(g * 65535.0 + 0.5);
- c.blue = (unsigned short)(b * 65535.0 + 0.5);
- c.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(auxState.display, auxState.current->colormap, &c);
- break;
- case GrayScale:
- case PseudoColor:
- if (index < auxState.current->glxVisual->colormap_size) {
- c.pixel = index;
- c.red = (unsigned short)(r * 65535.0 + 0.5);
- c.green = (unsigned short)(g * 65535.0 + 0.5);
- c.blue = (unsigned short)(b * 65535.0 + 0.5);
- c.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(auxState.display, auxState.current->colormap, &c);
- }
- break;
- }
-
- XSync(auxState.display, 0);
- XSetErrorHandler(old_handler);
- }
-
- void auxSetFogRamp(int density, int startIndex)
- {
- XErrorHandler old_handler;
- XColor c[4096];
- int rShift, gShift, bShift, intensity, fogValues, colorValues;
- int i, j, k;
-
- old_handler = XSetErrorHandler(Ignore);
-
- switch (auxState.current->glxVisual->class) {
- case DirectColor:
- fogValues = 1 << density;
- colorValues = 1 << startIndex;
- for (i = 0; i < colorValues; i++) {
- for (j = 0; j < fogValues; j++) {
- k = i * fogValues + j;
- intensity = i * fogValues + j * colorValues;
- if (intensity > auxState.current->glxVisual->colormap_size) {
- intensity = auxState.current->glxVisual->colormap_size;
- }
- intensity = (intensity << 8) | intensity;
- rShift = ffs((unsigned int)auxState.current->glxVisual->red_mask) - 1;
- gShift = ffs((unsigned int)auxState.current->glxVisual->green_mask) - 1;
- bShift = ffs((unsigned int)auxState.current->glxVisual->blue_mask) - 1;
- c[k].pixel = ((k << rShift) & auxState.current->glxVisual->red_mask) |
- ((k << gShift) & auxState.current->glxVisual->green_mask) |
- ((k << bShift) & auxState.current->glxVisual->blue_mask);
- c[k].red = (unsigned short)intensity;
- c[k].green = (unsigned short)intensity;
- c[k].blue = (unsigned short)intensity;
- c[k].flags = DoRed | DoGreen | DoBlue;
- }
- }
- XStoreColors(auxState.display, auxState.current->colormap, c,
- auxState.current->glxVisual->colormap_size);
- break;
- case GrayScale:
- case PseudoColor:
- fogValues = 1 << density;
- colorValues = 1 << startIndex;
- for (i = 0; i < colorValues; i++) {
- for (j = 0; j < fogValues; j++) {
- k = i * fogValues + j;
- intensity = i * fogValues + j * colorValues;
- if (intensity > auxState.current->glxVisual->colormap_size) {
- intensity = auxState.current->glxVisual->colormap_size;
- }
- intensity = (intensity << 8) | intensity;
- c[k].pixel = k;
- c[k].red = (unsigned short)intensity;
- c[k].green = (unsigned short)intensity;
- c[k].blue = (unsigned short)intensity;
- c[k].flags = DoRed | DoGreen | DoBlue;
- }
- }
- XStoreColors(auxState.display, auxState.current->colormap, c,
- auxState.current->glxVisual->colormap_size);
- break;
- }
-
- XSync(auxState.display, 0);
- XSetErrorHandler(old_handler);
- }
-
- void auxSetGreyRamp(void)
- {
- XErrorHandler old_handler;
- XColor c[4096];
- float intensity;
- int rShift, gShift, bShift, i;
-
- old_handler = XSetErrorHandler(Ignore);
-
- switch (auxState.current->glxVisual->class) {
- case DirectColor:
- for (i = 0; i < auxState.current->glxVisual->colormap_size; i++) {
- intensity = (float)i / (float)auxState.current->glxVisual->colormap_size *
- 65535.0 + 0.5;
- rShift = ffs((unsigned int)auxState.current->glxVisual->red_mask) - 1;
- gShift = ffs((unsigned int)auxState.current->glxVisual->green_mask) - 1;
- bShift = ffs((unsigned int)auxState.current->glxVisual->blue_mask) - 1;
- c[i].pixel = ((i << rShift) & auxState.current->glxVisual->red_mask) |
- ((i << gShift) & auxState.current->glxVisual->green_mask) |
- ((i << bShift) & auxState.current->glxVisual->blue_mask);
- c[i].red = (unsigned short)intensity;
- c[i].green = (unsigned short)intensity;
- c[i].blue = (unsigned short)intensity;
- c[i].flags = DoRed | DoGreen | DoBlue;
- }
- XStoreColors(auxState.display, auxState.current->colormap, c, auxState.current->glxVisual->colormap_size);
- break;
- case GrayScale:
- case PseudoColor:
- for (i = 0; i < auxState.current->glxVisual->colormap_size; i++) {
- intensity = (float)i / (float)auxState.current->glxVisual->colormap_size *
- 65535.0 + 0.5;
- c[i].pixel = i;
- c[i].red = (unsigned short)intensity;
- c[i].green = (unsigned short)intensity;
- c[i].blue = (unsigned short)intensity;
- c[i].flags = DoRed | DoGreen | DoBlue;
- }
- XStoreColors(auxState.display, auxState.current->colormap, c, auxState.current->glxVisual->colormap_size);
- break;
- }
-
- XSync(auxState.display, 0);
- XSetErrorHandler(old_handler);
- }
-
- void auxSetRGBMap(int size, float *rgb)
- {
- XErrorHandler old_handler;
- XColor c;
- int rShift, gShift, bShift, max, i;
-
- old_handler = XSetErrorHandler(Ignore);
-
- switch (auxState.current->glxVisual->class) {
- case DirectColor:
- max = (size > auxState.current->glxVisual->colormap_size) ?
- auxState.current->glxVisual->colormap_size : size;
- for (i = 0; i < max; i++) {
- rShift = ffs((unsigned int)auxState.current->glxVisual->red_mask) - 1;
- gShift = ffs((unsigned int)auxState.current->glxVisual->green_mask) - 1;
- bShift = ffs((unsigned int)auxState.current->glxVisual->blue_mask) - 1;
- c.pixel = ((i << rShift) & auxState.current->glxVisual->red_mask) |
- ((i << gShift) & auxState.current->glxVisual->green_mask) |
- ((i << bShift) & auxState.current->glxVisual->blue_mask);
- c.red = (unsigned short)(rgb[i] * 65535.0 + 0.5);
- c.green = (unsigned short)(rgb[size+i] *
- 65535.0 + 0.5);
- c.blue = (unsigned short)(rgb[size*2+i] *
- 65535.0 + 0.5);
- c.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(auxState.display, auxState.current->colormap, &c);
- }
- break;
- case GrayScale:
- case PseudoColor:
- max = (size > auxState.current->glxVisual->colormap_size) ?
- auxState.current->glxVisual->colormap_size : size;
- for (i = 0; i < max; i++) {
- c.pixel = i;
- c.red = (unsigned short)(rgb[i] * 65535.0 + 0.5);
- c.green = (unsigned short)(rgb[size+i] *
- 65535.0 + 0.5);
- c.blue = (unsigned short)(rgb[size*2+i] *
- 65535.0 + 0.5);
- c.flags = DoRed | DoGreen | DoBlue;
- XStoreColor(auxState.display, auxState.current->colormap, &c);
- }
- break;
- }
-
- XSync(auxState.display, 0);
- XSetErrorHandler(old_handler);
- }
-
- GLint auxGetColorMapSize(void)
- {
- if (!auxState.display) {
- return 0;
- } else {
- return auxState.current->glxVisual->colormap_size;
- }
- }
-
- void auxGetMouseLoc(int *x, int *y)
- {
- int junk;
-
- *x = 0;
- *y = 0;
- XQueryPointer(auxState.display, auxState.current->glxWindow,
- (Window *)&junk, (Window *)&junk,
- &junk, &junk, x, y, (unsigned int *)&junk);
- }
-